REF: remove DatetimeArray._with_freq, further freq management cleanup (GH#24566)#65276
Merged
Merged
Conversation
Index-level _with_freq no longer delegates to the array's _with_freq. It now performs the view + _freq assign directly, mirroring the as_unit pattern, and handles all validation (None, BaseOffset with m-dtype Tick check, 'infer' resolution, else ValueError) itself. Another step toward GH#24566: freq management continues to migrate from DTA/TDA up to the Index layer. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…e callers Three non-test callers go through the array's _with_freq helper: - blocks.maybe_coerce_values strips freq when wrapping into a Block - PeriodArray.to_timestamp assigns inferred freq on a fresh DTA - DatetimeIndex.normalize assigns inferred freq on a fresh DTA Replace each with direct `view()` + `_freq =` / `_freq =` assignment, which skips the array-level validation (all three pass fixed values so validation is a no-op) and leaves array._with_freq closer to being removable in a later step. Another step toward GH#24566. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
No core callers remain after the previous refactor. The ~10 test callers of array-level _with_freq are updated to use direct `_freq =` assignment (or `.view(); _freq =`) or `to_offset(inferred_freq)`. The `_union` fallback in DatetimeTimedeltaMixin now wraps the `super()._union` result via `_wrap_setop_result` before calling the Index-level `_with_freq`, since the base `_union` can return an ArrayLike rather than an Index. Removes ~29 lines from datetimelike.py array mixin. Another step toward GH#24566. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
freq defaults to None in both DatetimeArray._simple_new and TimedeltaArray._simple_new, so `freq=None` is redundant noise. Also removes several now-unnecessary type-ignore comments. Another step toward GH#24566. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Missed caller from the _with_freq removal sweep; switch to direct `_freq =` assignment to match the other array callers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mroeschke
approved these changes
Apr 18, 2026
Member
|
Thanks @jbrockmendel |
jbrockmendel
added a commit
to jbrockmendel/pandas
that referenced
this pull request
Apr 19, 2026
…566) In-place arithmetic on a DTA/TDA used to sync `_freq` from the arithmetic result. That belonged to the array's freq-management era; under the current design `_freq` is Index-managed dumb storage on the array. Mutating values via __iadd__/__isub__ leaves _freq alone (it can go stale), matching __setitem__'s behaviour after pandas-dev#65276's cleanup. Tests that compared `dta += x` vs `dta + x` for the pd.array boxed case now sync the expected freq from the iadd-result before comparison, since the rebound `dta + x` returns a freq-stripped array while the in-place version preserves the array's pre-iadd freq.
4 tasks
hamdanal
pushed a commit
to hamdanal/pandas
that referenced
this pull request
Jun 27, 2026
… (GH#24566) (pandas-dev#65276) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacks on top of #65266 and continues the GH#24566 effort to move freq management out of DatetimeArray/TimedeltaArray and onto the Index layer.
REF: make DatetimeTimedeltaMixin._with_freq self-contained— Index-level_with_freqstops delegating to the array's_with_freq. It does its ownview() + _freq =and handles all validation (None / BaseOffset+Tick-for-m-dtype / "infer" resolution / else ValueError) directly, mirroring theas_unitpattern.REF: stop calling DatetimeLikeArrayMixin._with_freq from non-test core callers— The three non-test core callers (blocks.maybe_coerce_values,PeriodArray.to_timestamp,DatetimeIndex.normalize) now manage_freqdirectly viaview()+_freq =orto_offset(inferred_freq).REF: remove DatetimeLikeArrayMixin._with_freq— With no remaining non-test callers, the array method is deleted (~29 lines). ~10 test callers updated to direct_freq =assignment. The_unionfallback now wrapssuper()._unionvia_wrap_setop_resultbefore calling Index-level_with_freq, since the base_unioncan return anArrayLikerather than an Index.CLN: drop redundant freq=None from DTA/TDA _simple_new call sites— 7 call sites wherefreq=Nonewas redundant noise (it's already the default), plus several now-obsolete# type: ignore[call-arg]comments.TST: update test_to_datetime_dta_tz for array-level _with_freq removal— One missed test caller.Test plan
pytest pandas/tests/arithmetic/ pandas/tests/resample/ pandas/tests/series/ pandas/tests/arrays/ pandas/tests/indexes/ pandas/tests/tseries/ pandas/tests/frame/ pandas/tests/internals/ pandas/tests/extension/ pandas/tests/tools/test_to_datetime.py— all passmypy pandas/core/arrays/datetimelike.py pandas/core/indexes/datetimelike.py pandas/core/arrays/datetimes.py pandas/core/arrays/timedeltas.py— no new errors🤖 Generated with Claude Code